#ifdef _WIN32
#ifndef STRAY_GRAPHICS_TEXTURE_DX9_H
#define STRAY_GRAPHICS_TEXTURE_DX9_H

#include <d3d9.h>

#include "../../SmartPtr/IntrusivePtr.h"
#include "../Texture.h"
#include "LostResource\LostResource.h"

namespace Stray {
namespace Core {
namespace Graphics {
namespace DirectX9 {

class TextureDX9 : public Stray::Core::Graphics::Texture, public LostResource
{
	friend class DeviceDX9;
	friend class ContextDX9;
private:
	TextureDX9(IDirect3DTexture9 *pTexture, const TextureDesc& desc, DeviceDX9 *pDevice);
	TextureDX9(IDirect3DSurface9 *pSurface, const TextureDesc& desc, DeviceDX9 *pDevice);
public:
	~TextureDX9();

	void releaseResource();
	void recoverResource();

	TextureDesc getDesc() const;
	RectData readRect(Stray::Rect *pRect);
	void writeRect(const void *pData, const Stray::Rect *pRect);

	void* getNativeHandle() const;
private:
	const Stray::Bool isTexture_;
	IDirect3DTexture9 *pTexture_;
	IDirect3DSurface9 *pSurface_;
	TextureDesc desc_;
	D3DSURFACE_DESC d3dDesc_;
	IDirect3DSurface9 *pBackup_;

	void backup();
};

typedef Stray::IntrusivePtr<TextureDX9>::type TextureDX9Ptr;

}
}
}
}

#endif
#endif